package com.everest.tribalapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Dering_Pengelola_4 extends Activity implements OnClickListener
{

	
	private Button next;
	protected String message;
	private Button previous;
	private TextView dering_peng_q4_1;
	private TextView dering_peng_q4_2a;
	private TextView dering_peng_q4_3a;
	private TextView dering_peng_q4_4;
	private CheckBox checkBox_2a4;
	private CheckBox checkBox_2b4;
	private CheckBox checkBox_2c4;
	private CheckBox checkBox_3a4;
	private CheckBox checkBox_3b4;
	private CheckBox checkBox_3c4;
	private CheckBox derlp4_checkBox_13h2;
	private EditText dering_f4_ans_1;
	private EditText dering_f4_ans_4;
	private int flag=0;
	protected int id;
	protected String[] choice;
	protected String selectvalue;
	private String value;
	private CharSequence[] MSG_VALUES_1={"Pernah","Tidak Pernah (Lanjut Ke No. V-1)"};
	private CharSequence[] MSG_VALUES_2={"Pengelolaan usaha fasilitas telepon ","Operasional perangkat telekomunikasi","Pemeliharaan perangkat"};
	private CharSequence[] MSG_VALUES_3={"Pembekalan teori","Pembekalan praktek / peragaan","Pembekalan buku panduan "};
	private CharSequence[] MSG_VALUES_4={"Sangat Kurang","Kurang","Cukup","Lengkap","Sangat lengkap"};
	protected int flag10b=0;
	protected int flag10a=0;
	protected String selectetdVal;
	protected boolean[] selectVal2={false,false,false};
	protected boolean[] selectVal3={false,false,false};
	
	
	@Override
	public void onBackPressed() 
	{
		
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Dering_Pengelola_4.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dering_pengelola_4);
		
		 initialization();
		 
	
		

previous.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent in=new Intent(getApplicationContext(),Dering_Pengelola_3.class);
		startActivity(in);
		Dering_Pengelola_4.this.finish();
	}
});

		 next.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent in=new Intent(getApplicationContext(),Dering_Pengelola_5.class);
					startActivity(in);
					Dering_Pengelola_4.this.finish();
				}
			});
		 
		
	}

	private void initialization() {

		dering_peng_q4_1=(TextView)findViewById(R.id.dering_peng_q4_1);
		dering_peng_q4_2a=(TextView)findViewById(R.id.dering_peng_q4_2a);
		dering_peng_q4_3a=(TextView)findViewById(R.id.dering_peng_q4_3a);
		dering_peng_q4_4=(TextView)findViewById(R.id.dering_peng_q4_4);		
		dering_f4_ans_1=(EditText)findViewById(R.id.dering_f4_ans_1);
		dering_f4_ans_4=(EditText)findViewById(R.id.dering_f4_ans_4);
		checkBox_2a4=(CheckBox)findViewById(R.id.checkBox_2a4);
		checkBox_2b4=(CheckBox)findViewById(R.id.checkBox_2b4);
		checkBox_2c4=(CheckBox)findViewById(R.id.checkBox_2c4);
		checkBox_3a4=(CheckBox)findViewById(R.id.checkBox_3a4);
		checkBox_3b4=(CheckBox)findViewById(R.id.checkBox_3b4);
		checkBox_3c4=(CheckBox)findViewById(R.id.checkBox_3c4);
		next=(Button)findViewById(R.id.next);
		previous=(Button)findViewById(R.id.previous);
		dering_peng_q4_1.setOnClickListener(this);
		dering_peng_q4_2a.setOnClickListener(this);
		dering_peng_q4_3a.setOnClickListener(this);
		dering_peng_q4_4.setOnClickListener(this);
		dering_f4_ans_1.setOnClickListener(this);
		dering_f4_ans_4.setOnClickListener(this);
		dering_f4_ans_1.setFocusable(false);
		dering_f4_ans_4.setFocusable(false);
		checkBox_2a4.setOnClickListener(this);
		checkBox_2b4.setOnClickListener(this);
		checkBox_2c4.setOnClickListener(this);
		checkBox_3a4.setOnClickListener(this);
		checkBox_3b4.setOnClickListener(this);
		checkBox_3c4.setOnClickListener(this);
		
				
	}

	@Override
	public void onClick(View v)
	{
		if(v.getId()==dering_peng_q4_1.getId())
		{
			value=getResources().getString(R.string.dering_peng_q4_1);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q4_2a.getId())
		{
			value=getResources().getString(R.string.dering_peng_q4_2a);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q4_3a.getId())
		{
			value=getResources().getString(R.string.dering_peng_q4_3a);
			toast_msg();
		}
		else if(v.getId()==dering_peng_q4_4.getId())
		{
			value=getResources().getString(R.string.dering_peng_q4_4);
			toast_msg();
		}
		else if(v.getId()==dering_f4_ans_1.getId())
		{
			msg_f4_ans_1();
		}
		else if(v.getId()==dering_f4_ans_4.getId())
		{
			msg_f4_ans_4();
		}
		
		else if(v.getId()==checkBox_2a4.getId())
		{
			checkBox_2a4.setChecked(false);
			msg_f4_ans_2();
		}
		else if(v.getId()==checkBox_2b4.getId())
		{
			checkBox_2b4.setChecked(false);
			msg_f4_ans_2();
		}
		else if(v.getId()==checkBox_2c4.getId())
		{
			checkBox_2c4.setChecked(false);
			msg_f4_ans_2();
		}
		else if(v.getId()==checkBox_3a4.getId())
		{
			checkBox_3a4.setChecked(false);
			msg_f4_ans_3();
		}
		else if(v.getId()==checkBox_3b4.getId())
		{
			checkBox_3b4.setChecked(false);
			msg_f4_ans_3();
		}
		else if(v.getId()==checkBox_3c4.getId())
		{
			checkBox_3c4.setChecked(false);
			msg_f4_ans_3();
		}
		
	}
	
	public void toast_msg()
	{
		LayoutInflater inflater = getLayoutInflater();

		View layout = inflater.inflate(R.layout.custom_toast,
				(ViewGroup) findViewById(R.id.custom_toast_layout_id));
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(value);
		Toast toast = new Toast(getApplicationContext());
		toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(layout);
		toast.show();
	}
	private void msg_f4_ans_1() {
	     Builder builder = new AlertDialog.Builder(this);
	     builder.setTitle("Select");
	     builder.setSingleChoiceItems(MSG_VALUES_1, -1, new DialogInterface.OnClickListener() {
	       

		@Override
	       public void onClick(DialogInterface dialog, int which) {
			 dering_f4_ans_1.setText(""+(which+1));
	         dialog.dismiss();
	         
	       }
	     });
	     builder.setNegativeButton("cancel",
	         new DialogInterface.OnClickListener() {
	           @Override
	           public void onClick(DialogInterface dialog, int which) {
	             dialog.dismiss();
	           }
	         });
	     AlertDialog alert = builder.create();
	     alert.show();
	   }
	private void msg_f4_ans_4() {
	     Builder builder = new AlertDialog.Builder(this);
	     builder.setTitle("Select");
	     builder.setSingleChoiceItems(MSG_VALUES_4, -1, new DialogInterface.OnClickListener() {
	       

		@Override
	       public void onClick(DialogInterface dialog, int which) {
			 dering_f4_ans_4.setText(""+(which+1));
	         dialog.dismiss();
	         
	       }
	     });
	     builder.setNegativeButton("cancel",
	         new DialogInterface.OnClickListener() {
	           @Override
	           public void onClick(DialogInterface dialog, int which) {
	             dialog.dismiss();
	           }
	         });
	     AlertDialog alert = builder.create();
	     alert.show();
	   }


	   private void msg_f4_ans_2()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_2, selectVal2,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal2[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_2.length; i++) 
		         {
		           if (selectVal2[i]) 
		           {
		              if(i==0)
		 				{
		            	 
		            	  checkBox_2a4.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_2b4.setChecked(true);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_2c4.setChecked(true);
		 				}
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		        		   checkBox_2a4.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_2b4.setChecked(false);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_2c4.setChecked(false);
		 				}
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
		   }
	   
	   private void msg_f4_ans_3()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_3, selectVal3,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal3[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_3.length; i++) 
		         {
		           if (selectVal3[i]) 
		           {
		              if(i==0)
		 				{
		            	 
		            	  checkBox_3a4.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_3b4.setChecked(true);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_3c4.setChecked(true);
		 				}
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		        		   checkBox_3a4.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_3b4.setChecked(false);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_3c4.setChecked(false);
		 				}
		 				
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
		   }
	
		@Override
		protected void onPause() {
			// TODO Auto-generated method stub
			super.onPause();
			SharedPreferences preferences=getSharedPreferences("dering_f4_details", MODE_PRIVATE);
			SharedPreferences.Editor editor=preferences.edit();
			editor.putString("4_1",dering_f4_ans_1.getText().toString().trim());
			editor.putBoolean("4_2a",checkBox_2a4.isChecked());
			editor.putBoolean("4_2b",checkBox_2b4.isChecked());
			editor.putBoolean("4_2c",checkBox_2c4.isChecked());
			editor.putBoolean("4_3a",checkBox_3a4.isChecked());
			editor.putBoolean("4_3b",checkBox_3b4.isChecked());
			editor.putBoolean("4_3c",checkBox_3c4.isChecked());
			editor.putString("4_4",dering_f4_ans_4.getText().toString().trim());
			editor.commit();
		}
		@Override
		protected void onResume() {
			// TODO Auto-generated method stub
			super.onResume();
			SharedPreferences preferences=getSharedPreferences("dering_f4_details",MODE_PRIVATE);
			dering_f4_ans_1.setText(preferences.getString("4_1",""));
			checkBox_2a4.setChecked(preferences.getBoolean("4_2a",false));
			checkBox_2b4.setChecked(preferences.getBoolean("4_2a",false));
			checkBox_2c4.setChecked(preferences.getBoolean("4_2a",false));
			checkBox_3a4.setChecked(preferences.getBoolean("4_2a",false));
			checkBox_3a4.setChecked(preferences.getBoolean("4_2a",false));
			checkBox_3a4.setChecked(preferences.getBoolean("4_2a",false));
			dering_f4_ans_4.setText(preferences.getString("4_4",""));

		}
}
